package io.renren;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.fastjson.JSON;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Properties;
import com.alibaba.druid.pool.ElasticSearchDruidDataSourceFactory;


/**
 * @Author: xlr
 * @Date: Created in 下午10:54 2018/8/31
 */
public class EsSQL {


    public static void main(String [] args) throws Exception{
        Properties properties = new Properties();
        properties.put("url", "jdbc:elasticsearch://localhost:9300/");
        DruidDataSource dds = (DruidDataSource) ElasticSearchDruidDataSourceFactory
                .createDataSource(properties);
        dds.setInitialSize(1);
        Connection connection = dds.getConnection();
        System.out.println();
        String sql2 = "select * FROM msg";
        PreparedStatement ps = connection.prepareStatement(sql2);
        ResultSet set=ps.executeQuery();

        ResultSetMetaData data= set.getMetaData();

        System.out.println( JSON.toJSONString(data));
        int count= set.getRow();

        System.out.println(count);
        System.err.println(data.getColumnCount());
        while (set.next()) {
            //sql对应输出
            System.out.println(set.getString("msg") );

        }

        ps.close();
        connection.close();
        dds.close();
    }

}
